package com.javabaas.server.novel_server.rank.controller;


import com.javabaas.server.novel_server.common.ModuleCode;
import com.javabaas.server.novel_server.common.ResponseJson;
import com.javabaas.server.novel_server.common.StatusCode;
import com.javabaas.server.novel_server.rank.entity.Rank;
import com.javabaas.server.novel_server.rank.entity.RankRepository;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/rank")
public class RankController {

    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    RankRepository rankRepository;

    @RequestMapping(value = "", method = RequestMethod.GET)
    @ApiOperation(value = "获取排行榜", notes = "")
    public Object getRank(HttpServletRequest request) {
        Map<String, Object> rankMap = new HashMap<>();
        logger.debug("get rank data in mongodb");
        List<Rank> rankList = new ArrayList<>();
        rankList = rankRepository.findByGenderEqualsOrderByPriorityAsc("male");
        rankMap.put("male", rankList);
        rankList = rankRepository.findByGenderEqualsOrderByPriorityAsc("female");
        rankMap.put("female", rankList);
        return ResponseJson.getResponseJson(ModuleCode.MODULE_RANK_STATUS, StatusCode.STATUS_OK, rankMap);
    }
}
